<?php
$this->breadcrumbs=array(
	'Services'=>array('index'),
	'Manage',
);

$this->menu=array(
	array('label'=>'List Service', 'url'=>array('index')),
	array('label'=>'Create Service', 'url'=>array('create')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('service-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>

<h1>Manage Services</h1>
<?php if(Yii::app()->user->hasFlash('service_admin_message')){ ?>

<div class="flash-success">
	<?php echo Yii::app()->user->getFlash('service_admin_message'); ?>
</div>

<?php } ?>

<p>
You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>

<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
	'model'=>$model,
)); ?>
</div><!-- search-form -->

<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'service-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'selectableRows'=>2,
	'columns'=>array(
        array(
        	'class'=>'CCheckBoxColumn', 
        	'id'=>'service_records',
        ),

		'id',
        array(
        	'name'=>'date',
        	'type'=>'datetime',
        	'value'=>'strtotime($data->date)',
        	'filter'=>'',
        ),
		//'date',
		//'purchaseDate',
		//'technicianId',
		'firstName',
		'LastName',
		array(
			'name' => 'status',
			'type'=>'raw',
			'value'=>'Service::getStatusArray($data->status)',
			'filter'=>Service::getStatusArray(),
		),
		array(
			'class'=>'CLinkColumn',
			'header' => 'Copy',
			'label'=>'Copy',     // text label of the button
			'urlExpression'=>'CHtml::normalizeUrl(array("service/copyService","id"=>$data->id))', 
		),
		array(
			'class'=>'CLinkColumn',
			'header' => 'Action',
			'labelExpression'=>'Service::getActionLabelFor($data)',     // text label of the button
			'urlExpression'=>'Service::getActionUrlFor($data)', 
		),
		
		
		/*
		'address',
		'suburb',
		'postcode',
		'state',
		'homePhone',
		'workPhone',
		'mobile',
		'email',
		'stairs',
		'productId',
		'serialNo',
		'generalComment',
		'partComment',
		'warranty',
		'faultDescription',
		'customerAccountNo',
		'storeTinNo',
		'otherInstruction',
		'dateCommenced',
		'dateCompleted',
		'chargeApplicable',
		'customerCharge',
		'fundsRecovered',
		'paymentType',
		'technicainPaid',
		'technicainPaidAmount',
		'workCarriedOut',
		'note',
		'storeId',
		'emailNote',
		'status',
		*/
		array(
			'class'=>'CButtonColumn',
			'deleteConfirmation'=>"Deleting Service will lead to deleting related Part Action record. \n Are you sure you want to delete this item?",
		),
	),
)); ?>
<?php
echo CHtml::beginForm($this->createUrl('exportRecords'),'post',array('id'=>'exportForm')); 
echo CHtml::hiddenField('exportServiceRecords','',array('id'=>'exportServiceRecords'));
echo CHtml::submitButton('Export Selected',array('id'=>'exportActionSubmit','name'=>'exportAction')); 
Yii::app()->clientScript->registerScript('preventExportFormSubmit','
$("#exportActionSubmit").click(function(eventArgs) {
	var values=[];
	$("[name=\"service_records[]\"]:checked").each(function(){
		values.push($(this).val());
	});
	if(values.length==0){
		alert("Please select records to export.");
		return false;
	}
	$("#exportServiceRecords").val(values.join(","));
});
');

?>

<?php echo CHtml::endForm(); ?>
